{
 "cells": [
  {
   "cell_type": "markdown",
   "id": "53cace86",
   "metadata": {},
   "source": [
    "________________\n",
    "* 2022/11/14/week13\n",
    "* Python学习记录\n",
    "________________"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "4acae8bc",
   "metadata": {},
   "source": [
    "# Head First Python练习\n",
    "# 1.Lists"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "id": "3f9cc9cb",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "i\n",
      "i\n",
      "a\n"
     ]
    }
   ],
   "source": [
    "# A-1\n",
    "vowels = [\"a\",\"e\",\"i\",\"o\",\"u\"]\n",
    "word = \"Milliways\"\n",
    "for letter in word:\n",
    "    if letter in vowels:\n",
    "        print(letter)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "id": "8bc5782a",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "i\n",
      "i\n",
      "a\n"
     ]
    },
    {
     "data": {
      "text/plain": [
       "['i', 'i', 'a']"
      ]
     },
     "execution_count": 3,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# A-2\n",
    "vowels = [\"a\",\"e\",\"i\",\"o\",\"u\"]\n",
    "found = []\n",
    "word = \"Milliways\"\n",
    "for letter in word:\n",
    "    if letter in vowels:\n",
    "        print(letter)\n",
    "        found.append(letter)\n",
    "found"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "id": "42c7fe91",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Don't panic\n",
      "['D', 'o', 'n', \"'\", 't', ' ', 'p', 'a', 'n', 'i', 'c']\n"
     ]
    }
   ],
   "source": [
    "# A-3\n",
    "phrase = \"Don't panic\"\n",
    "plist = list(phrase)\n",
    "print(phrase)\n",
    "print(plist)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "id": "a271f0eb",
   "metadata": {},
   "outputs": [],
   "source": [
    "plist.remove('D')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "id": "d516fb28",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "['o', 'n', \"'\", 't', ' ', 'p', 'a', 'n', 'i', 'c']"
      ]
     },
     "execution_count": 9,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "plist"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "id": "addd77e1",
   "metadata": {},
   "outputs": [],
   "source": [
    "for i in range(3):\n",
    "    plist.pop()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 11,
   "id": "2b6da8a0",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "['o', 'n', \"'\", 't', ' ', 'p', 'a']"
      ]
     },
     "execution_count": 11,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "plist"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 12,
   "id": "1730ad09",
   "metadata": {},
   "outputs": [],
   "source": [
    "plist.remove(\"'\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 13,
   "id": "42f44736",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "['o', 'n', 't', ' ', 'p', 'a']"
      ]
     },
     "execution_count": 13,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "plist"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 14,
   "id": "060c8eef",
   "metadata": {},
   "outputs": [],
   "source": [
    "plist.insert(3,plist[-1])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 15,
   "id": "0c826e76",
   "metadata": {},
   "outputs": [],
   "source": [
    "plist.insert(2,plist[-3])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 16,
   "id": "65dcd180",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "['o', 'n', ' ', 't', 'a', ' ', 'p', 'a']"
      ]
     },
     "execution_count": 16,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "plist"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 17,
   "id": "7ae5afd8",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'a'"
      ]
     },
     "execution_count": 17,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "plist.pop()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 18,
   "id": "d627debb",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "['o', 'n', ' ', 't', 'a', ' ', 'p']"
      ]
     },
     "execution_count": 18,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "plist"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 19,
   "id": "193c2e79",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "' '"
      ]
     },
     "execution_count": 19,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "plist.pop(-2)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 21,
   "id": "1be7a14a",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "['o', 'n', ' ', 't', 'a', 'p']"
      ]
     },
     "execution_count": 21,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "plist"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 22,
   "id": "5b1a8412",
   "metadata": {},
   "outputs": [],
   "source": [
    "new_phrase = ''.join(plist)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 23,
   "id": "eae195c7",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'on tap'"
      ]
     },
     "execution_count": 23,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "new_phrase"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 24,
   "id": "9e0a782c",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Don't panic!\n",
      "['D', 'o', 'n', \"'\", 't', ' ', 'p', 'a', 'n', 'i', 'c', '!']\n",
      "['o', 'n', 't', ' ', 'p', 'a']\n",
      "['o', 'n', 't', ' ', 'a', 'p']\n",
      "['o', 'n', ' ', 't', 'a', 'p']\n"
     ]
    },
    {
     "data": {
      "text/plain": [
       "'on tap'"
      ]
     },
     "execution_count": 24,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# A-3 整理  （列表的方法）\n",
    "phrase = \"Don't panic!\"\n",
    "plist = list(phrase)\n",
    "print(phrase)\n",
    "print(plist)\n",
    "for i in range(4):\n",
    "    plist.pop()\n",
    "plist.pop(0)\n",
    "plist.remove(\"'\")\n",
    "print(plist)\n",
    "plist.extend([plist.pop(),plist.pop()])\n",
    "print(plist)\n",
    "plist.insert(2,plist.pop(3))\n",
    "print(plist)\n",
    "# 列表元素的合并：''.join()\n",
    "''.join(plist)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 25,
   "id": "e8417a1d",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Don't panic!\n",
      "['D', 'o', 'n', \"'\", 't', ' ', 'p', 'a', 'n', 'i', 'c', '!']\n"
     ]
    }
   ],
   "source": [
    "# A-4 列表的切片和取值 on tap\n",
    "phrase = \"Don't panic!\"\n",
    "plist = list(phrase)\n",
    "print(phrase)\n",
    "print(plist)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 26,
   "id": "4d3847db",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'on tap'"
      ]
     },
     "execution_count": 26,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "''.join([plist[1],plist[2],plist[5],plist[4],plist[-5],plist[-6]])"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "b106a665",
   "metadata": {},
   "source": [
    "# 补练习，要检查"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "c09ff903",
   "metadata": {},
   "source": [
    "# 课后作业\n",
    "\n",
    "## Chapter 3: Structured Data 练习 （第三章的练习"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "b1f7fd5d",
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3 (ipykernel)",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.9.12"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
